package com.sw.small_world.fragment.me.myinfo;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sw.small_world.R;
import com.sw.small_world.activity.ClickButtonActivity;
import com.sw.small_world.adapter.MyEducationExAdapter;
import com.sw.small_world.adapter.MyJobExAdapter;
import com.sw.small_world.adapter.topicsquare.EducationExAdapter;
import com.sw.small_world.adapter.topicsquare.JobExAdapter;
import com.sw.small_world.fragment.base.BaseFragment;
import com.sw.small_world.utils.ConstantUtils;
import com.sw.small_world.utils.StartUtils;
import com.sw.small_world.widgets.CircleImageView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/3/27.
 */

public class MyInfoFragment extends BaseFragment {

    @Bind(R.id.iv_portrait)
    CircleImageView ivPortrait;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_field)
    TextView tvField;
    @Bind(R.id.tv_company)
    TextView tvCompany;
    @Bind(R.id.tv_position)
    TextView tvPosition;
    @Bind(R.id.tv_tele)
    TextView tvTele;
    @Bind(R.id.tv_address)
    TextView tvAddress;
    @Bind(R.id.rl_edit_my_info)
    RelativeLayout rlEditMyInfo;
    @Bind(R.id.tv_mai_zhi)
    TextView tvMaiZhi;
    @Bind(R.id.tv_my_friends)
    TextView tvMyFriends;
    @Bind(R.id.add_job_ex)
    TextView addJobEx;
    @Bind(R.id.list_view_job_experience)
    ListView listViewJobExperience;
    @Bind(R.id.add_edu_ex)
    TextView addEduEx;
    @Bind(R.id.list_view_education_experience)
    ListView listViewEducationExperience;
    private ClickButtonActivity activity;
    private ArrayList<String> jobExList = new ArrayList<>();
    private ArrayList<String> eductionExList = new ArrayList<>();
    private MyJobExAdapter jobExAdapter;
    private MyEducationExAdapter educationExAdapter;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (ClickButtonActivity) getActivity();
        activity.tvTitle.setText("个人资料");
    }

    @Override
    protected Object requestData() {
        for (int i = 0; i < 2; i++) {
            jobExList.add("" + i);
            eductionExList.add("" + i);
        }
        return ConstantUtils.STATE_SUCCESSED;
    }

    @Override
    protected View getSuccessView() {
        View view = View.inflate(activity, R.layout.fragment_my_info, null);
        ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        jobExAdapter = new MyJobExAdapter(jobExList, activity);
        educationExAdapter = new MyEducationExAdapter(eductionExList, activity);
        listViewJobExperience.setAdapter(jobExAdapter);
        listViewEducationExperience.setAdapter(educationExAdapter);
        listViewJobExperience.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                StartUtils.startActivityById(activity, ConstantUtils.ADD_JOB_EX);
            }
        });
        listViewEducationExperience.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                StartUtils.startActivityById(activity, ConstantUtils.ADD_EDU_EX);
            }
        });
    }
    @OnClick({R.id.rl_edit_my_info,R.id.add_edu_ex,R.id.add_job_ex})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_edit_my_info:
                StartUtils.startActivityById(activity, v.getId());
                break;
            case R.id.add_edu_ex:
                StartUtils.startActivityById(activity, ConstantUtils.ADD_EDU_EX);
                break;
            case R.id.add_job_ex:
                StartUtils.startActivityById(activity, ConstantUtils.ADD_JOB_EX);
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
